﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch3
{
    class Rectangle
    {
        public readonly float Width, Height;
        public Rectangle(float width, float height) //构造器
        {
            Width = width;
            Height = height;
        }
        public void Deconstruct(out float width, out float height) //解构器
        {
            width = Width;
            height = Height;
        }
    }
    class Chapt03_1ClassDeconstructor
    {

        static void _Main()
        {
            Rectangle rect = new Rectangle(3, 4);
            (float width, float height) = rect;//解构器调用
            Console.WriteLine(width + " " + height);

            //解构器调用方法2
            float a, b;
            rect.Deconstruct(out a, out b);
            Console.WriteLine(a + " " + b);

            //解构器调用方法3
            rect.Deconstruct(out var c, out var d);
            Console.WriteLine(c + " " + d);

            (var e, var f) = rect;  //解构器允许隐式类型推断
            var (g, h) = rect;
            Console.WriteLine(g + " " + h);

            (width, height) = rect;
            Console.WriteLine(width + " " + height);
        }
    }
}
